<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
		<script>
			/* 理解闭包
			function fn1(){
				var a = 1
				var b = "abc"
				function fn2(){
					console.log(a)
				}
			}
			fn1()
			*/
			
			// 将函数作为另一个函数的返回值
			function fn1(){
				// 闭包产生
				var a = 2;
				function fn2(){
					a++
					console.log(a)
				}
				return fn2
			}
			var f = fn1()
			
			f()  // 3
			f()  // 4
			f = null  // 闭包死亡
			
			
			/* 将函数作为实参传递给另一个函数调用
			function showDelay(msg, time){
				setTimeout(function(){
					alert(msg)
				}, time)
			}
			showDelay("atgguigu", 2000)
			*/
		</script>
	</head>
	<body>
	</body>
</html>
